﻿namespace Test30.Engine
{
    public class SwapStatAction : Action
    {
        public SwapStatAction(Hero hero, Stat stat)
            : base(hero)
        {
            _stat = stat;
        }

        protected override ActionResult OnProcess()
        {
            Hero hero = (Hero)Entity;

            // restore to max
            _stat.Restore();

            if (_stat.Base < Stat.BaseMax)
            {
                // pick a stat to drain
                int i = Rng.Int(hero.Stats.Count - 1);
                if (hero.Stats[i] == _stat)
                {
                    // picked the stat being raised, so skip it
                    i++;
                }

                // drain one
                hero.Stats[i].Base--;

                // to raise another
                _stat.Base++;

            }

            return ActionResult.Done;
        }

        private readonly Stat _stat;
    }
}
